<?php
declare(strict_types=1);

namespace App\Dao;

use App\Model\Article;

class ArticleDao
{
    /**
     * 修改记录
     * @Author abell
     * @DateTime 2020-06-16
     * @param array $where
     * @param array $data
     * @return bool
     */
    public function editOne($where,$data){
        return Article::query()->where($where)->update($data);
    }

    /**
     * 查询一条记录
     * @Author abell
     * @DateTime 2020-06-16
     * @param array $where
     * @param array $select
     * @return object
     */
    public function searchOne($where,$select=['*']){
        return Article::query()->where($where)->select($select)->get();
    }

    /**
     * 资讯新增数据
     * @Author abell
     * @DateTime 2020-06-16
     * @param array $data
     * @return int
     */
    public function addArticle($data){
        return Article::query()->insertGetId($data);
    }

    /**
     * 资讯列表
     * @Author abell
     * @DateTime 2020-06-16
     * @param int $pageSize
     * @param int $page
     * @param array $where
     * @param string $order
     * @return array
     */
    public function searchByWherePage($pageSize,$page,$where,$order){
        return Article::query()->where($where)->orderByRaw($order)->paginate(intval($pageSize),['*'],'page',$page)->toArray();
    }
}
